package com.amadeus.spin.standard.util.logging;

import org.apache.log4j.PatternLayout;
import org.apache.log4j.spi.LoggingEvent;

/**
 * This custom pattern was originaly intended to make the FileAppender use 2
 * different ConversionPattern according to the package of the class using the
 * logger. It's seamless for a ConsoleAppender (create a different logger in the
 * log4j.properties for each package requiring a specific conversion pattern).
 * It is not possible via the log4j.properties.for a FileAppender (unless you
 * log in two different files)
 */
public class Log4jCustomLayout extends PatternLayout {

  @Override
  public String format(LoggingEvent event) {
    String result = "";
    String loggerName = event.getLoggerName();
    if ((loggerName.contains("com.amadeus.spin.devtool.soap.shooter.process"))
        || (loggerName.contains("com.amadeus.spin.devtool.soap.shooter.validate"))) {
      this.setConversionPattern("[%p] +[%c{1}] %m%n");
      result = super.format(event);
    }
    else {
      this.setConversionPattern("[%p] %m%n");
      result = super.format(event);
    }

    return result;
  }

}
